package homework.yuandan.controller;

import com.alibaba.druid.util.StringUtils;
import homework.yuandan.beans.ActionRight;
import homework.yuandan.beans.Movie;
import homework.yuandan.beans.Users;
import homework.yuandan.beans.dto.UserDTO;
import homework.yuandan.common.ResponseEnum;
import homework.yuandan.common.vo.ResultVO;
import homework.yuandan.config.TokenContainer;
import homework.yuandan.exception.AppException;
import homework.yuandan.service.MovieService;
import homework.yuandan.service.RoleService;
import homework.yuandan.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 作者:49293
 * 时间:2021/1/3-13:36
 *
 * @author 49293
 */
@CrossOrigin
@RestController
@RequestMapping("/main/test")
@Api(tags = "这是主要的接口")
public class MainController {
    @Resource
    MovieService movieService;
    @Resource
    UserService userService;
    @Resource
    TokenContainer tokenContainer;
    @Resource
    RoleService roleService;

    @GetMapping("/isShowing")
    @ApiOperation("获取当前热映的接口")
    public ResultVO<List<Movie>> isShowing() {
        return movieService.viewNowPlaying();
    }

    @GetMapping("/comingSoon")
    @ApiOperation("获取即将上映的接口")
    public ResultVO<List<Movie>> comingSoon() {
        return movieService.viewComingPlay();
    }

    @PostMapping("/info")
    @ApiOperation("根据id获取详情")
    public ResultVO<Movie> getInfo(Integer movieId) {
        return movieService.viewInfo(movieId);
    }

    @PostMapping("/login")
    @ApiOperation("登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", required = true, paramType = "query"),
            @ApiImplicitParam(name = "password", required = true, paramType = "query")
    })
    public ResultVO<UserDTO> login(String username, String password) {
        return userService.check(username, password);
    }

    @GetMapping("/getRight")
    @ApiOperation("获取对应的权限按钮")
    private ResultVO<List<ActionRight>> getRight() {
        return roleService.selectByRoleId();
    }
}
